package com.atguigu.redis;

import com.atguigu.constant.RedisConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author ：Hachimen
 * @date ：Created in 2021/9/13 19:34
 * @description：
 * @modified By：
 * @version:
 */
@Component
public class RedisMessageReceiver {
    @Autowired
    private RedisTemplate redisTemplate;

    public void receiveChannelMessage(String message) {
        //拿到的值 ""24:1""
        if(!StringUtils.isEmpty(message)){
            message = message.replaceAll("\"", "");
            String[] split = message.split(":");
            if(split.length==2){
                //splitMessage[0]商品的skuId,splitMessage[1]状态位(是否可以秒杀)
               redisTemplate.opsForValue().set(RedisConst.SECKILL_STATE_PREFIX+split[0],split[1]);
            }
        }
    }
}
